package test;

import org.junit.*;

import dsa.LinkedList;
import dsa.List;

import static org.junit.Assert.*;


public class JimBatistickTest {
    
    private LinkedList testing;
    
    public JimBatistickTest() {
    }
    
    @Before
    public void setUp() {
       
        
        testing = new LinkedList();
        
        testing.addLast("0");
        testing.addLast("1");
        testing.addLast("2");
        testing.addLast("3");
    }
    
    @After
    public void tearDown() {
    }

    
	@Test
	public void TestingGet() {

		
		for(int i = 0; i < testing.size(); i++)
		{
			assertEquals(i + "", testing.get(i));
		}
		
		assertEquals("0", testing.getFirst());
		assertEquals("3", testing.getLast());
		
		
		
		
	}
	@Test
	public void testingIndexOf()
	{
		
		//testing every value
		assertEquals(0, testing.indexOf("0"));
		assertEquals(1, testing.indexOf("1"));
		assertEquals(2, testing.indexOf("2"));
		assertEquals(3, testing.indexOf("3"));
			
		
		
		//no index case
		assertEquals(-1, testing.indexOf("Nothing in the List"));
				
		
		
		
	}
	
	@Test
	public void testingContains()
	{
		assertTrue(testing.contains("0"));
		assertFalse(testing.contains("6"));
		assertTrue(testing.contains("1"));
		assertTrue(testing.contains("2"));
		assertFalse(testing.contains("4"));
		assertTrue(testing.contains("3"));
		
		
	}
	
	@Test
	public void testingCounters()
	{
		assertEquals(4, testing.size());
		testing.addLast("4");
		testing.addLast("5");
		testing.removeLast();
		assertEquals(5, testing.size());
		
		testing.addLast("5");
		assertEquals(6, testing.size());
		

		for(int i = testing.size(); i > 0; i--)
		{
			testing.removeLast();
		}
	
		assertEquals(0, testing.size());
		
	}
	
	
	@Test
	public void testingClone()
	{
		List clone = (LinkedList)testing.clone();
		
		for(int i = 0; i < testing.size(); i++)
		{
			
			//tests every element in original to the same element in the clone
			assertEquals(testing.get(i), clone.get(i));
			
		}
		
		assertTrue(clone.size() == testing.size());
		
		
	}
	
	@Test
	public void testingSet()
	{
		Object temp;
		testing.set(0, "first");
		testing.set(testing.size()-1, "fifth");
		
		assertTrue(testing.get(0).equals("first"));
		
		temp = testing.get(2);
		
		assertEquals(temp, testing.set(2, "changed"));
		
		
	}
	@Test
	public void testingToArray()
	{
		Object arrayTest[] = testing.toArray();
		
		for(int i = 0; i < testing.size(); i++)
		{
			
			//tests every element in original to the same element in the array
			assertEquals(testing.get(i), arrayTest[i]);
			
		}
		
	}
	
	@Test
	public void testingAddFirst()
	{
		testing.addFirst("top");
		assertTrue(testing.get(0).equals("top"));
		
		testing.addFirst(0101);
		assertTrue(testing.get(0).equals(0101));
	}
	
	@Test
	public void testingAddLast()
	{
		testing.addLast("last");
		assertEquals("last", testing.get(testing.size()-1));
		
		testing.addLast(1234);
		assertEquals(1234, testing.get(testing.size()-1));
	}
	
	@Test
	public void testingRemove()
	{
		testing.addFirst("removing first");
		assertEquals("removing first", testing.removeFirst());
		
		testing.addLast("removing last");
		assertEquals("removing last",testing.removeLast());
		
		
		for(int i = testing.size() - 1; i >= 0; i--)   
		{                                                       
			testing.remove(i);
		}
		
	
		assertEquals(0, testing.size());
		
		
	}
	

}
